
class ShelvePlugin(object):
    def __init__(self, indexer):
        import shelve
        self.indexer = indexer
        self._shelve = shelve.open("%s/%s/docs.shelve" % (self.indexer.index_home, self.indexer.index_name), protocol=2)

    def process_doc(self, doc):
        self._shelve[doc.get_xaphash()] = doc.get_raw_document()

        
class AspellPlugin(object):
    def __init__(self, indexer):
        import aspell
        self.indexer = indexer
        self._aspell = aspell.spell_checker()

    def process_doc(self, doc):
        for token in doc.tokeniter():
            # TODO: call aspell and save the stemmed forms somewhere
            self._aspell.suggest(token)

class StemmerPlugin(object):
    def __init__(self, indexer):
        self.indexer = indexer
        self.stemmer = StemmerMap(self.indexer.index_home, self.indexer.index_name)
        self.bulk_stemmap = {}

    def process_doc(self, doc):
        tokeniter = doc.tokeniter()
        for t in tokeniter:
            # pass the term into the stemmer map to build a probability list
            stemmed_form = self.stemmer.stem(t)
            self.bulk_stemmap.setdefault(stemmed_form, {})
            self.bulk_stemmap[stemmed_form][t] = bulk_stemmap[stemmed_form].get(t, 0) + 1

        # TODO: batch save the stemmer map somewhere for safekeeping
        # bulk load the stemmer map
        #self.stemmer.bulk_load(bulk_stemmap)
